package com.wz.wzliving.commodity.controller;

import com.aliyun.oss.OSSClient;
import com.wz.wzliving.commodity.entity.BrandEntity;
import com.wz.wzliving.commodity.service.BrandService;
import com.wzcommon.utils.PageUtils;
import com.wzcommon.utils.R;
import com.wzcommon.valid.SaveGroup;
import com.wzcommon.valid.UpdateGroup;
import com.wzcommon.valid.UpdateIsShowGroup;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 家居品牌
 *
 * @author wangzeng
 * @email 3107187288@qq.com
 * @date 2025-03-27 09:42:24
 */
@RestController
@RequestMapping("commodity/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        BrandEntity brand = brandService.getById(id);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("commodity:brand:save")
    public R save(@Validated(SaveGroup.class) @RequestBody BrandEntity brand) {

            brandService.save(brand);
            return R.ok();


    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@Validated(UpdateGroup.class) @RequestBody BrandEntity brand) {
        brandService.updateById(brand);

        return R.ok();
    }
/*
isshow
 */
    @RequestMapping("/update1/isshow")

    public R updateisshow(@Validated(UpdateIsShowGroup.class) @RequestBody BrandEntity brand) {
        brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("commodity:brand:delete")
    public R delete(@RequestBody Long[] ids) {
        brandService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

//    @Resource
//    private OSSClient ossClient;

//    @RequestMapping("/test1")
//    public R testUpload1() throws Exception {
//        FileInputStream fileInputStream = new FileInputStream("E:\\localpath\\hello.txt");
//        ossClient.putObject("wzliving-100", "hello.txt", fileInputStream);
//        ossClient.shutdown();
//        return R.ok("sucess");
//    }


}
